﻿

using System;
using System.Text;
using System.Reflection;
using Microsoft.Practices.Unity.InterceptionExtension;
using System.Runtime.Caching;

using System.Collections.Generic;

namespace DanGao.Infrastructure.Log
{

    public class LogBehavior : IInterceptionBehavior
    {

        public IEnumerable<Type> GetRequiredInterfaces()
        {
            return Type.EmptyTypes;
        }

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var returnValue = getNext().Invoke(input, getNext);
            if(returnValue.Exception != null )
            {
                LogUtils.GetInstance(LogType.Text).Log(returnValue.Exception);
            }
            return returnValue;
        }

        public bool WillExecute
        {
            get { return true; }
        }
    }

}
